/** ***********************************************************************************
* @file         flash_config.h
* @brief        FLASH 地址分配空间
* @details      主要用来进行对FLASH 空间地址的划分
* @author       杨小珛
* @date         2020/03/07
* @copyright    北京高知科技有限公司    
* @version      V1.0
* @attention    无
**************************************************************************************/

#ifndef FLASH_CONFIG_H
#define FLASH_CONFIG_H

#define SPI_FLASH_SIZE               0x00200000UL    // SPI Flash 大小 2MB
#define SPI_FLASH_BASE_ADDR          0x00000000UL    // SPI Flash 起始地址
#define SPI_FLASH_MIN_SECTOR         4096             // SPI Flash 最小扇区4K

/*-------------------------------------------------------------------------
                系统区( System area )
  -----------------------------------------------------------------------*/
//------------------------------------------------------------------------------
/* 系统区: 系统参数存储区*/
/* 4 K */
#define SF_SYS_PARA_FLAG_SECTORS       1
#define SF_SYS_PARA_FLAG_ADDR          ( SPI_FLASH_BASE_ADDR + 0 )
#define SF_SYS_PARA_FLAG_SIZE          ( SPI_FLASH_MIN_SECTOR * 1 )

//------------------------------------------------------------------------------
/* 系统区: 系统参数的备份区 */
/* 4 K */
#define SF_SYS_PARA_BACKUP_FlAG_SECTORS        1
#define SF_SYS_PARA_BACKUP_ADDR                ( SF_SYS_PARA_FLAG_ADDR + SF_SYS_PARA_FLAG_SIZE )
#define SF_SYS_PARA_BACKUP_SIZE                ( SPI_FLASH_MIN_SECTOR * SF_SYS_PARA_BACKUP_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 系统区: 系统存储SFB HANDLE 数据存储区 */
/* 4 K */
#define SF_SFB_HANDLE_FlAG_SECTORS        1
#define SF_SFB_HANDLE_ADDR                 ( SF_SYS_PARA_BACKUP_ADDR + SF_SYS_PARA_BACKUP_SIZE )
#define SF_SFB_HANDLE_SIZE                 ( SPI_FLASH_MIN_SECTOR * SF_SFB_HANDLE_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: 用于存储补传数据存储区 */
/* 1 M */
#define SF_SAVE_DATA_FlAG_SECTORS         256
#define SF_SAVE_DATA_ADDR                  ( SF_SFB_HANDLE_ADDR + SF_SFB_HANDLE_SIZE )
#define SF_SAVE_DATA_SIZE                  ( SPI_FLASH_MIN_SECTOR * SF_SAVE_DATA_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: GNSS数据存储区 */
/* 4 * 8K */
#define SF_GNSS_DATA_FlAG_SECTORS         8
#define SF_GNSS_DATA_ADDR                  ( SF_SAVE_DATA_ADDR + SF_SAVE_DATA_SIZE )
#define SF_GNSS_DATA_SIZE                  ( SPI_FLASH_MIN_SECTOR * SF_GNSS_DATA_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: ERROR CODE数据存储区 */
/* 4 K */
#define SF_ERROE_DATA_FlAG_SECTORS         1
#define SF_ERROE_DATA_ADDR                  ( SF_GNSS_DATA_ADDR + SF_GNSS_DATA_SIZE )
#define SF_ERROE_DATA_SIZE                  ( SPI_FLASH_MIN_SECTOR * SF_ERROE_DATA_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: CAN CONFIG数据存储区 */
/* 4 K */
#define SF_CANCFG_DATA_FlAG_SECTORS         1
#define SF_CANCFG_DATA_ADDR                 ( SF_ERROE_DATA_ADDR + SF_ERROE_DATA_SIZE )
#define SF_CANCFG_DATA_SIZE                 ( SPI_FLASH_MIN_SECTOR * SF_CANCFG_DATA_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: SYS TIMESTAMP数据存储区 */
/* 4 K */
#define SF_TIMESTAMP_DATA_FlAG_SECTORS      1
#define SF_TIMESTAMP_DATA_ADDR              ( SF_CANCFG_DATA_ADDR + SF_CANCFG_DATA_SIZE )
#define SF_TIMESTAMP_DATA_SIZE              ( SPI_FLASH_MIN_SECTOR * SF_TIMESTAMP_DATA_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: QXWZ CFG数据存储区 */
/* 4 K */
#define SF_QXWZ_CFG_DATA_FlAG_SECTORS      1
#define SF_QXWZ_CFG_DATA_ADDR              ( SF_TIMESTAMP_DATA_ADDR + SF_TIMESTAMP_DATA_SIZE )
#define SF_QXWZ_CFG_DATA_SIZE              ( SPI_FLASH_MIN_SECTOR * SF_QXWZ_CFG_DATA_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: QXWZ GPDRC数据存储区 */
/* 4 K */
#define SF_QXWZ_GPDRC_DATA_FlAG_SECTORS      1
#define SF_QXWZ_GPDRC_DATA_ADDR              ( SF_QXWZ_CFG_DATA_ADDR + SF_QXWZ_CFG_DATA_SIZE )
#define SF_QXWZ_GPDRC_DATA_SIZE              ( SPI_FLASH_MIN_SECTOR * SF_QXWZ_GPDRC_DATA_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: QXWZ GPDRC4数据存储区 */
/* 4 K */
#define SF_QXWZ_GPDRC4_DATA_FlAG_SECTORS     1
#define SF_QXWZ_GPDRC4_DATA_ADDR             ( SF_QXWZ_GPDRC_DATA_ADDR + SF_QXWZ_GPDRC_DATA_SIZE )
#define SF_QXWZ_GPDRC4_DATA_SIZE             ( SPI_FLASH_MIN_SECTOR * SF_QXWZ_GPDRC4_DATA_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: SIM CARD数据存储区 */
/* 4 K */
#define SF_SIM_CARD_DATA_FlAG_SECTORS       1
#define SF_SIM_CARD_DATA_ADDR               ( SF_QXWZ_GPDRC4_DATA_ADDR + SF_QXWZ_GPDRC4_DATA_SIZE )
#define SF_SIM_CARD_DATA_SIZE               ( SPI_FLASH_MIN_SECTOR * SF_SIM_CARD_DATA_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: ETC数据存储区 */
/* 4 * 50K */
#define SF_ETC_DATA_FlAG_SECTORS            50
#define SF_ETC_DATA_ADDR                    ( SF_SIM_CARD_DATA_ADDR + SF_SIM_CARD_DATA_SIZE )
#define SF_ETC_DATA_SIZE                    ( SPI_FLASH_MIN_SECTOR * SF_ETC_DATA_FlAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: LBS密钥KEY存储区 */
/* 4 K */
#define SF_LBS_KEY_FLAG_SECTORS             1
#define SF_LBS_KEY_ADDR                     ( SF_ETC_DATA_ADDR + SF_ETC_DATA_SIZE )
#define SF_LBS_KEY_SIZE                     ( SPI_FLASH_MIN_SECTOR * SF_LBS_KEY_FLAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: ETC SN存储区 */
/* 4 K */
#define SF_ETC_SN_FLAG_SECTORS             1
#define SF_ETC_SN_ADDR                     ( SF_LBS_KEY_ADDR + SF_LBS_KEY_SIZE )
#define SF_ETC_SN_SIZE                     ( SPI_FLASH_MIN_SECTOR * SF_ETC_SN_FLAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: 存储车辆信息数据*/
#define SF_VIN_DATA_FLAG_SECTORS            1
#define SF_VIN_DATA_ADDR                     ( SF_ETC_SN_ADDR + SF_ETC_SN_SIZE )
#define SF_VIN_DATA_SIZE                    ( SPI_FLASH_MIN_SECTOR * SF_VIN_DATA_FLAG_SECTORS )

//------------------------------------------------------------------------------
/* 数据区: 存储设备重启标识*/
#define SF_RESET_REASON_LAG_SECTORS         1
#define SF_RESET_REASON_ADDR                ( SF_VIN_DATA_ADDR + SF_VIN_DATA_SIZE ) 
#define SF_RESET_REASON_SIZE                ( SPI_FLASH_MIN_SECTOR * SF_RESET_REASON_LAG_SECTORS )

/*FLASH空间数据的使用总长度*/
#define	SF_TOTAL_LENGTH_USED_LEN	( SF_RESET_REASON_ADDR + SF_RESET_REASON_SIZE )

/*防止FLASH空间数据溢出错误警告*/
#if( SF_TOTAL_LENGTH_USED_LEN > SPI_FLASH_SIZE )
#error Out of flash maximum space range (Maximum data length:0x20000000UL)
#endif


#endif





